<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>证书信息列表</title>
    <%@ include file="../../../header.jsp" %>
</head>
<body class="body-main">
<div class="titleSearch">
    <form id="titleSearch">
        <div class="layui-inline">
            <label>地区：</label>
            <div class="layui-input-inline">
                <div class="bus-plugIn" id="certificateArea">
                    <input type="hidden" name="certificateAreaId" class="plug-in-msg"/>
                    <input type="hidden" name="certificateArea" class="plug-in-code"/>
                    <input type="text" readonly placeholder="请选择" class="chose-plugIn layui-input" id="certificateAreaChange" name="areaName">
                    <div class="bus-picker">
                        <div class="bus-picker-tab">
                            <a href="javascript:void(0);" class="active">请选择</a>
                        </div>
                        <div class="bus-picker-content"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-inline">
            <label>证书类型：</label>
            <div class="layui-input-inline">
                <select class="select-style" name="certificateType1" id="certificateType1"
                        onchange="loadCertificateType('190px','#certificateType1','${generalType}',1,'#certificateSpecialtys1',0,'#certificateLevel1')">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label>证书专业：</label>
            <div class="layui-input-inline">
                <select class="select-style" name="certificateSpecialtys1" id="certificateSpecialtys1" onchange="checkCertificateSpecialty('#certificateType1','#certificateSpecialtys1')" style="width:150px">
                    <option value="">请先选择证书类型</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label>证书等级：</label>
            <div class="layui-input-inline">
                <select class="select-style" name="certificateLevel1" id="certificateLevel1" style="width:150px">
                    <option value="">请先选择证书类型</option>
                </select>
            </div>
        </div>
    </form>
    <div class="layui-inline">
        <button class="layui-btn layui-btn-mini layui-btn-normal" onclick="search('#myTable','reload')">搜索</button>
        <button class="layui-btn layui-btn-mini layui-btn-primary" onclick="cleanSearchWithHidden()">清空</button>
    </div>
</div>
<d:hasUrlAuth authCode="ZZSC_ZS_OPERATION">
    <div class="table-conter">
        <d:hasUrlAuth authCode="ZZSC_ZS_SYZS">
            <a href="javascript:void(0)" class="layui-btn layui-btn-mini" onclick="addWarehousing()">新增配置</a>
        </d:hasUrlAuth>
    </div>
</d:hasUrlAuth>

<table id="myTable" class="cell-border crm-table">
</table>
<%@ include file="../../../footer.jsp" %>

<script src="${rootUrl}/static/js/zzsc/production/sc_common.js?v=${version}"></script>
<script src="${rootUrl}/static/js/zzsc/credential/credentailCommon/credentailCommon.js?v=${version}"></script>
<script src="${rootUrl}/static/js/zzsc/credential/generalCertificate/editGeneralCertificate.js?v=${version}"></script>
<script src="${rootUrl}/static/js/zzsc/credential/generalCertificate/generalCertificateInfo.js?v=${version}"></script>
<script src="${rootUrl}/static/js/zzsc/common/sc_chooseUser.js?v=${version}" type="text/javascript" charset="utf-8"></script>
<script>
    $(function () {
        $('#myTable').dataTableExtend({
            "ajax": {
                "url": "${rootUrl}/zs/general_credential/warehousing_data.do",
                "type": "post"
            }, "fnServerParams": function (aoData) {
                var checkResult = checkHasSybAuth($('#signOrgId option'));
                if (!checkResult) {
                    aoData = $.extend(aoData, {"isAll": "0"});
                }
                aoData = $.extend(aoData, $('.titleSearch').serialize2object());
                return aoData;
            },
            "pageLength": 20,//每页显示的条数默认是10条，有特殊业务需要显示不同条数的列表才应该加入该参数
            "scrollX": true,//是否开启横项滚动
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "rightColumns": 1//右侧锁定1列
            },
            "aoColumns": [
                {
                    "title": "序号",
                    "orderable": false,
                    "width": "60",
                    "render": function (data, type, full, meta) {
                        return meta.row + 1;
                    }
                },
                {
                    "title": "地区",
                    "data": "applicationScope",
                    "orderable": false,
                    "width": "120"
                },
                {
                    "title": "证书名称",
                    "data": "certificateType",
                    "orderable": false,
                    "width": "120"
                },
                {
                    "title": "证书等级",
                    "data": "certificateLevel",
                    "orderable": false,
                    "width": "120"
                },
                {
                    "title": "证书专业",
                    "data": "certificateSpecialtys",
                    "orderable": false,
                    "width": "120"
                },
                {
                    "title": "证书数量",
                    "data": "stockQuantity",
                    "orderable": false,
                    "width": "120"
                },
                {
                    "title": "最新操作时间",
                    "data": "updateTime",
                    "orderable": false,
                    "width": "120"
                },
                {
                    "title": "最新操作人",
                    "data": "updateName",
                    "orderable": false,
                    "width": "120"
                },
                {
                    "title": "操作",
                    "orderable": false,
                    "data": {},
                    "render": function (data, type, row, meta) {
                        var operation = '<a class="iboss-link" href="javascript:void(0)" id="editWarehousing" onclick="editWarehousing(\'' + row.id + '\')">编辑</a>';
                        return operation ;
                    }
                }
            ],
        });
        //异步加载
        Plug.plug_ins(
            "get",
            "${cmsBaseUrl}/api/cms/tree_book/v1/get_tree_book_list.do?code=2147483647&type=2&level=1",
            "#certificateArea",
            '请选择地区',
            function () {
            },
            true, '2147483647'
        );
        loadCertificateType('100%', '#certificateType1', '${generalType}', 0);
    });
    // 新增配置
    function addWarehousing() {
        DGG.loading();
        $.post(sysInfo.basePath + "/zs/general_credential/add_warehousing.html", function (data) {
            dgg.Open({
                title: '新增配置',
                content: data,
                area: '500px',
                btn: ["确定", "取消"],
                yes: function () {
                    DGG.loading('close');
                    addWarehousing1()
                }
            });
        }, 'html');
    }
    function addWarehousing1() {
        var params = $("#credentialForm").serializeObject();
        if (params.certificateArea === ''){
            DGG.Tip("请选择地区",$('#certificateArea1'),{tips: [3, '#000'], time: 3000});
            return;
        }
        if (params.certificateType === ''){
            alert("请选择证书类型")
            return;
        }
        if (params.certificateSpecialtys === ''){
            alert("请选择证书专业")
            return;
        }
        if (params.certificateLevel === ''){
            alert("请选择证书等级")
            return;
        }
        if (params.stockQuantity === ''){
            DGG.Tip("请选择库存数量",$('#stockQuantity'),{tips: [3, '#000'], time: 3000});
            return;
        }
        params.certificateSpecialty = getVal('#certificateSpecialtys', 0);
        addWarehousing2(params)
    }
    function addWarehousing2(params) {
        $.post(sysInfo.basePath + "/zs/general_credential/addWarehousing2.do", params, function (result) {
            if (result.code == 0) {
                DGG.Succeed('添加成功');
                search('#myTable', 'reload');
                setTimeout(function () {
                    layer.closeAll();
                }, 500);
            } else {
                DGG.Errors(result.msg);
            }
            DGG.loading('close');
        });
    }
    // bianji
    function editWarehousing(id) {
        DGG.loading();
        $.post(sysInfo.basePath + "/zs/general_credential/edit_warehousing.html", {id: id}, function (result) {
            var index = dgg.Open({
                type: 1,
                title: '编辑配置',
                btn: ["确定", "取消"],
                content: result,
                area: '500px',
                yes: function () {
                    DGG.loading("close");
                    // 修改证书
                    var params = $("#credentialForm").serializeObject();
                    updateWarehousing(params);
                }, end: function () {
                    layer.closeAll("tips");
                }
            });
        });
    }
    function updateWarehousing(params) {
        if (params.certificateType === ''){
            alert("请选择证书类型")
            return;
        }
        if (params.certificateSpecialtys === ''){
            alert("请选择证书专业")
            return;
        }
        if (params.certificateLevel === ''){
            alert("请选择证书等级")
            return;
        }
        if (params.stockQuantity === ''){
            DGG.Tip("请选择库存数量",$('#stockQuantity'),{tips: [3, '#000'], time: 3000});
            return;
        }

        params.certificateSpecialty = params.certificateSpecialtys.toString();
        $.post(sysInfo.basePath + "/zs/general_credential/updateWarehousing.do", params, function (result) {
            if (result.code == 0) {
                DGG.Succeed('修改成功');
                search('#myTable', 'reload');
                setTimeout(function () {
                    layer.closeAll();
                }, 500);
            } else {
                DGG.Errors(result.msg);
            }
            DGG.loading('close');
        });
    }

</script>
</body>
</html>